package extend.php
{
	import flash.net.*;
	import mortal.common.global.*;
	
	public class PHPSender extends Object
	{
		private static const FRXZ_SO:String = "frxz_so";
		private static var _hasSend:Boolean = true;
		private static var _userNameObject:Object;
		private static var _allUser:Object;
		private static var _infoMap:Object = {};
		public static var isCreateRole:Boolean = false;
		private static var _myShareObject:SharedObject;
		
		public function PHPSender()
		{
		}
		
		public static function sendToURLByPHP(type:int, info:String = "") : void
		{
			var str:String;
			var typeInfo:String;
			if (isSend(ParamsConst.instance.username, type) == false)
			{
				
			}
			try
			{
				if (ParamsConst.instance.dothingUrl != null && ParamsConst.instance.dothingUrl != "")
				{
					str = ParamsConst.instance.dothingUrl + "&do=" + type;
					str = str + ("&type=" + type + "&username=" + encodeURI(ParamsConst.instance.username) + "&phpID=" + ParamsConst.instance.phpID);
					if (info != "")
					{
						str = str + ("&info=" + encodeURI(type + "->" + info));
					}
					else
					{
						typeInfo = SenderType.getInfoByType(type);
						str = str + ("&info=" + encodeURI(type + "->" + ParamsConst.instance.username + "->" + typeInfo));
					}
					sendToURL(new URLRequest(str));
				}
			}
			catch (e:Error)
			{
				trace(e.message);
			}
		}
		
		public static function isSend(userKey:String, nameObjectKey:int) : Boolean
		{
			if (_myShareObject == null)
			{
				_myShareObject = SharedObject.getLocal(FRXZ_SO);
			}
			if (_allUser == null)
			{
				_allUser = _myShareObject.data["userNameObject"];
				if (_allUser == null)
				{
					_allUser = {};
				}
			}
			if (_userNameObject == null)
			{
				_userNameObject = _allUser[userKey];
				if (_userNameObject == null)
				{
					_userNameObject = {};
					_allUser[userKey] = _userNameObject;
				}
			}
			if (_userNameObject[nameObjectKey])
			{
				return false;
			}
			_userNameObject[nameObjectKey] = true;
			_myShareObject.data.userNameObject = _allUser;
			_myShareObject.flush(10000);
			return true;
		}
		
		public static function sendGift() : void
		{
			if (ParamsConst.instance.loginGiftUrl != null && ParamsConst.instance.loginGiftUrl != "")
			{
				sendToURL(new URLRequest(ParamsConst.instance.loginGiftUrl + "&username=" + ParamsConst.instance.username));
			}
		}
	}
}
